package learn1;

import java.io.File;

//File的常用的方法
public class test2 {
    public static void main(String[] args) {
        String path1 = "C:/Users/free_day/Desktop/javaFile_test/test1.txt";
        String path2 = "C:\\Users\\free_day\\Desktop\\javaFile_test\\test1.txt";


        //1.对一个文件的路径进行判断
        path1 = "C:/Users/free_day/Desktop/javaFile_test/test1.txt";
        File file1 = new File(path1);
        System.out.println(file1.isFile());
        System.out.println(file1.isDirectory());
        System.out.println(file1.exists());

        System.out.println("-----------------");
        //2.对一个文件夹的路径进行判断
        path1 = "C:\\Users\\free_day\\Desktop\\javaFile_test";
        File file2 = new File(path1);
        System.out.println(file2.isFile());
        System.out.println(file2.isDirectory());
        System.out.println(file2.exists());

        System.out.println("-----------------");
        //3.对一个不存在的路径进行判断
        path1 = "C:\\Users\\free_day\\Desktop\\javaFile_test\\test";
        File file3 = new File(path1);
        System.out.println(file3.isFile());
        System.out.println(file3.isDirectory());
        System.out.println(file3.exists());

        System.out.println("-----------------");
        //4.返回文件的大小（字节数量），无法获取文件夹的大小
        System.out.println(file1.length());

        //获取文件的绝对路径
        System.out.println(file1.getAbsolutePath());

        //获取文件的名称
        System.out.println(file1.getName());

    }
}



























